/*
    Copyright  Louis CHEREL cherel.louis@gmail.com  
    This file is part of Agenda de l'Efrei.

    Agenda de l'Efrei is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Agenda de l'Efrei is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Agenda de l'Efrei.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.efrei.AgendaEfrei;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.*;
import android.preference.PreferenceManager;
import android.util.Log;

public class AutoStart extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent_) 
    {
        
        
        
        Intent resultIntent = new Intent(context, CheckNotes.class);
        
        PendingIntent resultPendingIntent = PendingIntent.getService(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        
        
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);  // get User's Preferences
        Boolean mNotif = sharedPref.getBoolean(context.getString(R.string.pref_notif_KEY), false);
        Log.v("AutoStart", "loaded");
        if(mNotif)
        {
            long mNotifNext = sharedPref.getLong(context.getString(R.string.pref_next_notif_KEY), 0);
            AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            alarmManager.set(AlarmManager.RTC, mNotifNext, resultPendingIntent);
            Log.v("AutoStart", "Alarm Chosen");
        }
    }
}
